package cn.itcast.service.cargo.impl;

import cn.hutool.core.util.IdUtil;
import cn.itcast.dao.cargo.GoodsDao;
import cn.itcast.domain.cargo.Goods;
import cn.itcast.domain.cargo.GoodsExample;
import cn.itcast.service.cargo.GoodsService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    private GoodsDao goodsDao;
    @Override
    public void delete(String id) {
        goodsDao.deleteByPrimaryKey(id);

    }

    @Override
    public void save(Goods goods) {
        goods.setId(IdUtil.simpleUUID());
        goodsDao.insertSelective(goods);

    }

    @Override
    public void update(Goods goods) {
        goodsDao.updateByPrimaryKeySelective(goods);

    }

    @Override
    public Goods findById(String id) {
        return goodsDao.selectByPrimaryKey(id);
    }

    @Override
    public List<Goods> findAll(GoodsExample example) {
        return goodsDao.selectByExample(example);
    }

    @Override
    public PageInfo findByPage(int pageNum, int pageSize, GoodsExample example) {
        PageHelper.startPage(pageNum, pageSize);
        List<Goods> list = goodsDao.selectByExample(example);
        return new PageInfo(list);
    }
}
